package cn.eu.common.query.model;

import cn.eu.common.query.annotation.Join;
import cn.eu.common.query.annotation.QueryJoin;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Setter
public class QueryJoinModel {

    private Map<String, TableModel> tableModelMap = new HashMap<>();

    private TableModel main;

    private List<JoinModel> join;

    public QueryJoinModel(QueryJoin queryJoin) {
        this.main = new TableModel(queryJoin.main());
        this.tableModelMap.put(this.main.getAlias(), this.main);
        this.join = new ArrayList<>();
        for (Join join : queryJoin.join()) {
            this.join.add(new JoinModel(this.tableModelMap, this.main, join));
        }
    }

}
